package nmsu.ppe.agendabuddy;

import java.util.Calendar;
import android.app.Activity;
import android.os.Bundle;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TimePicker;
import android.content.Intent;
import android.view.View;

public class NewEventActivity extends Activity
{       
        private Calendar actualDate, viewDate;
        private DBAdapter dba = new DBAdapter(this);
        
        /** Called whenever the activity is created. */
/**		  
* @param savedInstanceState saved current info, uses for activity creation
**/		  
		  
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
                super.onCreate(savedInstanceState);
                
                // set the view that will be seen
                setContentView(R.layout.new_event);
                
                Bundle extras = getIntent().getExtras();
                viewDate = (Calendar) extras.get("Calendar");
                DatePicker dateBox = (DatePicker)findViewById(R.id.datePicker_CreateEventDate);
                dateBox.init(viewDate.get(Calendar.YEAR), viewDate.get(Calendar.MONTH), viewDate.get(Calendar.DATE), null);
        }
/**
* @param v used to help navigate views
**/
        public void newEventCreateClicked(View v)
        {
                /** Ethan this is where you put the code to enter stuff into the data base from the 
                 *      blanks in the new_event view
                 */
                
                // desc should be limited to 68 chars.
                        
                dba.open();
                
                DatePicker dateBox = (DatePicker)findViewById(R.id.datePicker_CreateEventDate);
                TimePicker timeBox = (TimePicker)findViewById(R.id.timePicker_CreateEventTime);
                EditText descriptionBox = (EditText)findViewById(R.id.editText_CreateEventDescription);
                
                String time = "";
                if(timeBox.getCurrentHour() < 10)
                        time += "0";
                time += timeBox.getCurrentHour() + ":";
                if(timeBox.getCurrentMinute() < 10)
                        time += "0";
                time += timeBox.getCurrentMinute();
                
                long eid = dba.addEvent(dateBox.getMonth() + ":" + dateBox.getDayOfMonth() + ":" + dateBox.getYear(),
                                time, descriptionBox.getText().toString().replaceAll("\n", " "), "TEMP", "TEMP");
                
                dba.close();
                Intent intent = new Intent();
        setResult(RESULT_OK, intent);
        finish();
        }

        public void newEventBackClicked(View v)
        {
                Intent intent = new Intent();
        setResult(RESULT_OK, intent);
        finish();
        }
}